import os, time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"  # 浏览器驱动位置
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")

# 警告框
link = driver.find_element_by_link_text('设置')
ActionChains(driver).move_to_element(link).perform()

driver.find_element_by_link_text('搜索设置').click()
time.sleep(2)
driver.find_element_by_class_name('prefpanelgo').click()
time.sleep(2)
t = driver.switch_to.alert.text
driver.switch_to.alert.accept()

# 如果是confirm弹窗 accept表示接受 dismiss表示取消
print(t)
driver.quit()
